#include <map>
#include <string>
#include <iostream>
using namespace std;

int main()
{
    int n,m;
    while (cin >> n){
        string hat;
        map<int, string> mice;
        typedef map<int, string>::reverse_iterator rIter;
        for (int i=0; i<n; i++){
            cin >> m >> hat;
            mice[m]=hat;
        }
        for (rIter it=mice.rbegin(); it!=mice.rend(); ++it)
            cout << it->second << endl;
    }
}
